<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="反馈内容">
        <el-input
          type="textarea"
          :rows="5"
          placeholder="请输入内容"
          v-model="userfeedback.feedbackContent">
        </el-input>
      </el-form-item>
      <el-form-item label="反馈结果">
        <el-input
          type="textarea"
          :rows="5"
          placeholder="请输入内容"
          v-model="userfeedback.handleResult">
        </el-input>
      </el-form-item>
      <el-form-item label="处理状态">
        <el-input v-model="userfeedback.feedbackStatus"/>
      </el-form-item>
      <el-form-item>
        <!--防止表单重复提交（如何保证接口的幂等性）-->
        <el-button :disabled="saveBtnDisabled" type="primary" @click="saveOrUpdate">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import userfeedback from '../../api/userfeedback'

  export default {
    data() {
      return {
        userfeedback: {},
        saveBtnDisabled: false
      }
    },
    created() {
      // 要获取路由里面的ID参数 this.$route.params
      console.log(this.$route.params)
      // 需要进行一个判断，因为进入这个页面，一不定有ID参数
      if (this.$route.params && this.$route.params.id) {
        // 根据ID查询培训师的数据
        userfeedback.getById(this.$route.params.id).then(res => {
          this.userfeedback = res.data;
        });
      }
    },

    methods: {
      saveOrUpdate() {
        this.saveBtnDisabled = true;// 设置保存按钮不可以被点击
        // 异步提交
        userfeedback.saveOrUpdate(this.userfeedback).then(res => {
          this.saveBtnDisabled = false;// 不管成功还是失败，都要把该按钮置为可以被点击
          // 1. 显示提示信息
          this.$message.success(res.message);
          // 2. 跳转到培训师的列表页面
          // this.$router 表示整个路由（路由器）
          // this.route 表示某一个路由地址
          this.$router.push({path: '/userfeedback/list'})
        }).catch(() => {
          this.saveBtnDisabled = false;// 不管成功还是失败，都要把该按钮置为可以被点击
        });
      },
    }
  }
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
